import './index.less'
import React, { useEffect, useState } from 'react';
import { Button, Tabs } from 'antd';
import { useNavigate } from 'react-router-dom';
import { model } from '@/services/financialApi';
import { use } from 'echarts';
const Template = () => {
    const searchParams = new URLSearchParams(location.search);
    const id = Number(searchParams.get('id'))
    console.log(id);
    let id1 = 0
    const [data1, setData1] = useState<any>([])
    const mod = (id1: number) => {
        if (id != null) {
            model({ accType: id, sobId: 1, type: id1 }).then(({ data }) => {
                console.log(data.list);
                let _data = []
                for (let i = 0; i < data.list.length; i += 2) {
                    _data.push({ ...data.list[i], subName2: data.list[i + 1].subName })
                }
                setData1(_data)

            })
        }
    }
    useEffect(() => {
        mod(id1)

    }, [])
    const onChange = (key: any) => {
        id1 = (key - 1)
        mod(id1)
    };
    const navigate = useNavigate();
    const go = () => {
        navigate(-1);
    }
    const items = [
        {
            key: '1',
            label: '收入',
            children: <div>
                <div className='btn'>
                    <Button className='new'>新增</Button>
                    <Button onClick={go}>返回</Button>
                </div>
                <div className='min'>
                    {
                        data1.map((v: any) => <div className='min-1'>
                            <div className='min-1-1'>
                                <span>{v.catName}</span>
                                <div>
                                    <a>修改</a>
                                    <a>删除</a>
                                </div>
                            </div>
                            <div className='min-1-2'>
                                <p>借: {v.subName}</p>
                                <p>贷: {v.subName2}</p>
                            </div>
                        </div>)
                    }
                </div>
            </div>,
        },
        {
            key: '2',
            label: 'Tab 2',
            children: <div>
                <div className='btn'>
                    <Button>新增</Button>
                    <Button>返回</Button>
                </div>
                <div className='min'>
                    {
                        data1.map((v: any) => <div className='min-1'>
                            <div className='min-1-1'>
                                <span>{v.catName}</span>
                                <div>
                                    <a>修改</a>
                                    <a>删除</a>
                                </div>
                            </div>
                            <div className='min-1-2'>
                                <p>借: {v.subName}</p>
                                <p>贷: {v.subName2}</p>
                            </div>
                        </div>)
                    }
                </div>
            </div>,
        },
    ]
    return (
        <div className='tem'>
            <div className="text1">现金日记账</div>
            <Tabs
                className='tabs'
                onChange={onChange}
                type="card"
                items={items}
            />
        </div>
    )
}
export default Template